package com.apex.shared.mybatis.config;

import com.p6spy.engine.logging.Category;
import com.p6spy.engine.spy.appender.FormattedLogger;

import java.io.PrintStream;

/**
 * Apex CustomLooger
 *
 * @author Bangda Xiao
 */
public class CustomLogger extends FormattedLogger {

    protected PrintStream getStream() {
        return System.out;
    }

    @Override
    public void logSQL(int connectionId, String now, long elapsed, Category category, String prepared, String sql, String url) {
        logText(new CustomMessageFormatter().formatMessage(connectionId, now, elapsed, null, prepared, sql, url));
    }

    @Override
    public void logException(Exception e) {
        e.printStackTrace(getStream());
    }

    @Override
    public void logText(String text) {
        getStream().println(text);
    }

    @Override
    public boolean isCategoryEnabled(Category category) {
        return true;
    }
}
